##HarbridgeYong_Bipartisanship_LegSuccess_94_12_Replication.R
##Harbridge-Yong, Laurel Congressional Capacity Chapter replication files for analysis of bipartisanship
## and legislative success in the U.S. Congress
##Data come from Fowler cosponsorship data (through 108th Congress), and updated web scrape from Harbridge-Yong (through 112th), using same format as Fowler

##Load data
##set working directory
setwd("C:/Box Sync/My Documents/Congressional capacity scholars group/Replication Files")
data<- read.csv("HarbridgeYong_Bipartisanship_LegSuccess_94_112_Data.csv", header=TRUE)
names(data)

#########################################
##Variables defined as follows:
##cong - Congress (94-112)
##diff.mean - Difference in means on DW-NOMINATE (House of Representatives), from voteview
##prop.plaw.all - proportion of bills that passed the House (H.R) that became public law
##prop.plaw.bipart.all - proportion of bipartisan cosponsored bills that passed the House (H.R.) that became public law
##prop.plaw.part.all - proportion of partisan cosponsored bills that passed the House (H.R.) that became public law
##prop.part.co.20.percent.roll.congress.all - proportion of House bills (H.R.) receiving a roll call vote that were partisan in cosponsorship coalition

##NOTE: bipartisan cosponsorship if at least 20% of the cosponsors are from the party opposite the bill's sponsor; 
## partisan cosponsorship otherwise (see Harbridge 2015)
##########################################

##########################################
##    Analyses used in chapter          ##
##########################################
##Figure 14.1 

##tiff(file="HarbridgeYong_Fig1_percent public law if passed house 94 112.tiff", height=3.2, width=6.5, units="in", res=330)
tiff(file="HarbridgeYong_ch14_001.tiff", height=3.2, width=6.5, units="in", res=330)
par(mfrow=c(1,2), las=1,
    oma=c(2,2,1.5,0.1),              ##outer margins
    mar=c(4.5,4.5,1.5,1.5)+0.1,        ##margin for each graph
    tck=-0.01,                   ##size of tick mark
    #mgp=c(2.3,1,0.2),              ##where labels are
    mex=.6,                      ##label numbers distance
    cex.lab=.8)
plot(data$prop.plaw.all*100 ~ data$cong,
     ylim=c(0,100),
     ylab="Percentage",
     main="House Bills Becoming Public Law",
     cex.main=.7,
     cex.lab=.8,
     xaxt="n",
     xlab="Congress",
     type="l",
     lty=1)
axis(1, seq(94,112,by=2), cex=.9)
plot(data$prop.plaw.bipart.all*100 ~ data$cong,
     ylim=c(0,100),
     ylab="Percentage",
     main="Cosponsored House Bills Becoming Public Law",
     cex.main=.7,
     cex.lab=.8,
     xaxt="n",
     xlab="Congress",
     type="l",
     lty=1)
axis(1, seq(94,112,by=2), cex=.7)
lines(data$prop.plaw.part.all*100 ~ data$cong,
      type="l",
      lty=2,
      add=T)
legend(102, 99, c("Bipartisan Bills", "Partisan Bills"), lty=c(1,2), cex=.7, bty="n")
dev.off()

##Correlations reported in text
##Polarization and proportion of House passed bills becoming law
cor.test(data$prop.plaw.all, data$diff.means, use="pairwise") ##-0.64 (p=0.003)

##Polarization and proportion of bipartisan House passed bills becoming law
cor.test(data$prop.plaw.bipart.all, data$diff.means, use="pairwise") ##-0.12 (p=0.62)

##Polarization and proportion of bipartisan House passed bills becoming law
cor.test(data$prop.plaw.part.all, data$diff.means, use="pairwise") ##-0.77 (p<0.001)

##Partisan agenda setting (proportion of bills recieving roll call vote with partisan cosponsorship) and legislative success
# (proportion of House passed bills becoming public law)
cor.test(data$prop.plaw.part.al, data$prop.part.co.20.percent.roll.congress.all, use="pairwise") ##-0.56 (p=.01)





